package book;

public class ShareVariableTest {

	static class MyTask implements Runnable{

//		private AtomicInteger count = new AtomicInteger(10);
//		private Lock lock = new ReentrantLock();
		private int count = 10;
		
		@Override
		public void run() {
			
//			while(count.get() > 0){
			while(count --> 0){
				
//				lock.lock();
//				try {
//					if (count.get() > 0) {
//
//						count.decrementAndGet();
//						System.out.println(Thread.currentThread().getName() + "：" + count.get());
						System.out.println(Thread.currentThread().getName() + "：" + count);
//					} 
//				} finally {
//					lock.unlock();
//				}
			}
		}
	}
	
	public static void main(String[] args) {
		
		MyTask task = new MyTask();
		Thread t1 = new Thread(task);
		Thread t2 = new Thread(task);
		Thread t3 = new Thread(task);
		Thread t4 = new Thread(task);
		Thread t5 = new Thread(task);
		t1.start();
		t2.start();
		t3.start();
		t4.start();
		t5.start();
	}
}
